package com.ds.infrastructure.hyperspace.console.model.request.stage;

import com.ds.infrastructure.hyperspace.console.entity.enums.TbPublicEnum;
import com.ds.infrastructure.hyperspace.console.entity.table.TbStage;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

/**
 * @author: yaozhendong
 * @create: 2019-09-20 09:38
 **/
@Data
@NoArgsConstructor
public class UpdateStageForm {
    @ApiModelProperty(example = "20")
    @NotNull
    private Long id;
    @NotBlank
    @Pattern(regexp = "^[a-z-]{2,20}$", message = "不满足正则表达式:^[a-z-]{2,20}$")
    private String stageName;

    private String description;

    public static TbStage toEntity(UpdateStageForm form) {
        TbStage tbStage = new TbStage();
        tbStage.setId(form.getId());
        tbStage.setStageName(form.getStageName());
        tbStage.setDescription(form.getDescription());
        return tbStage;

    }

    public static TbStage toEntity4SelectOne(UpdateStageForm form, Long environmentId) {
        TbStage tbStage = new TbStage();
        tbStage.setEnvironmentId(environmentId);
        tbStage.setStageName(form.getStageName());
        tbStage.setGmtIsDeleted(TbPublicEnum.GMD_IS_DEL.NO.code);
        return tbStage;
    }
}
